package com.hydl.power.service.impl;

import com.github.pagehelper.PageInfo;
import com.hydl.power.mapper.CityMapper;
import com.hydl.power.mapper.MaintenanceReportMapper;
import com.hydl.power.mapper.SysUserMapper;
import com.hydl.power.pojo.City;
import com.hydl.power.pojo.MaintenanceReport;
import com.hydl.power.pojo.SysUser;
import com.hydl.power.service.CityService;
import com.hydl.power.service.MaintenanceReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MaintenanceReportServiceImpl implements MaintenanceReportService {

    @Autowired
    private MaintenanceReportMapper maintenanceReportMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public PageInfo<MaintenanceReport> queryOpsReport(Integer pageNum, Integer pageSize, String cityId, String projectId, String roomId, String dataType, String time, String token) {
        SysUser sysUser =sysUserMapper.getUserByToken(token);
        List<MaintenanceReport> list=new ArrayList<>();
        if(sysUser!=null){
            if(sysUser.getStatus()==2) {
                 list =maintenanceReportMapper.queryOpsReport(pageNum,pageSize,cityId,sysUser.getProjectId().toString(),roomId,dataType,time);
                for (MaintenanceReport maintenanceReport : list) {
                    if(maintenanceReport.getSumOrderStatus()==null){
                        maintenanceReport.setSumOrderStatus("0");
                    }
                    if(maintenanceReport.getSumTime()==null){
                        maintenanceReport.setSumTime("0");
                    }
                    maintenanceReport.setSumTime(String.valueOf(Integer.parseInt(maintenanceReport.getSumTime())/60));
                }
                return new PageInfo<>(list);
            }
        }
            list =maintenanceReportMapper.queryOpsReport(pageNum,pageSize,cityId,projectId,roomId,dataType,time);
        for (MaintenanceReport maintenanceReport : list) {
            if(maintenanceReport.getSumOrderStatus()==null ){
                maintenanceReport.setSumOrderStatus("0");
            }
            if(maintenanceReport.getSumTime()==null){
                maintenanceReport.setSumTime("0");
            }
            maintenanceReport.setSumTime(String.valueOf(Integer.parseInt(maintenanceReport.getSumTime())/60));
        }
        return new PageInfo<>(list);
    }
}
